package com.hw.sssd.controller;


import com.hw.sssd.entity.User;
import com.hw.sssd.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import java.util.List;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Order;
import org.springframework.data.domain.Sort.Direction;
@Controller

public class IndexController {
    @Autowired
    private UserService userService;

    @RequestMapping("list")
    @ResponseBody
    public String index(Integer page){

        Page<User> list = userService.list(page);
        return "index";
    }
    @RequestMapping("add")
    @ResponseBody
    public User index(User user){
        return userService.save( user );
    }
    @RequestMapping("update")
    @ResponseBody
    public Page<User> update(User user, Integer page){
        userService.update( user );
        return userService.list(page);
    }
}
